package com.dgz.system.controller.sysuser;

import com.dgz.common.core.constants.HttpConstants;
import com.dgz.common.core.controller.BaseController;
import com.dgz.common.core.domain.R;
import com.dgz.common.core.domain.vo.LoginUserVo;
import com.dgz.system.domain.sysuser.dto.LoginDTO;
import com.dgz.system.domain.sysuser.dto.SysUserSaveDTO;
import com.dgz.system.domain.sysuser.vo.SysUserVO;
import com.dgz.system.service.sysuser.ISysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: DongGuoZhen
 * @Date: 2024/12/05/10:39
 * @Description:
 */

@Tag(name = "管理员接口")
@RestController
@RequestMapping("/sysUser")
public class SysUserController extends BaseController {


    @Autowired
    private ISysUserService sysUserService;

    @Operation(summary = "管理员登录", description = "根据账号密码进行管理员登录")
    @PostMapping("/login")
    @ApiResponse(responseCode = "1000", description = "登录成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙，请稍后再试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    public R<String> login(@RequestBody LoginDTO loginDTO) {
        return sysUserService.login(loginDTO.getUserAccount(), loginDTO.getPassword());
    }


    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return toR(sysUserService.logout(token));
    }

    @GetMapping("/info")
    public R<LoginUserVo> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.info(token);
    }


    @Operation(summary = "新增管理员", description = "根据提供的信息新增管理员⽤⼾")
    @PostMapping("/add")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "⽤⼾已存在")
    public R<Void> add(@Validated @RequestBody SysUserSaveDTO saveDTO) {
        return toR(sysUserService.add(saveDTO));
    }


    @DeleteMapping("/{userId}")
    @Operation(summary = "删除⽤⼾", description = "通过⽤⼾id删除⽤⼾")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.PATH, description = "⽤⼾ID")})
    @ApiResponse(responseCode = "1000", description = "成功删除⽤⼾")
    @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
    @ApiResponse(responseCode = "3101", description = "⽤⼾不存在")
    public R<Void> delete(@PathVariable Long userId) {
        return null;
    }




    @Operation(summary = "⽤⼾详情", description = "根据查询条件查询⽤⼾详情")
    @GetMapping("/detail")
    @Parameters(value = {
            @Parameter(name = "userId", in = ParameterIn.QUERY, description = "⽤⼾ID"),
            @Parameter(name = "sex", in = ParameterIn.QUERY, description = "⽤⼾性别")})
            @ApiResponse(responseCode = "1000", description = "成功获取⽤⼾信息")
            @ApiResponse(responseCode = "2000", description = "服务繁忙请稍后重试")
            @ApiResponse(responseCode = "3101", description = "⽤⼾不存在")
            public R<SysUserVO> detail(Long userId, @RequestParam(required = false)
            String sex) {
        return null;
    }
}
